#include <iostream>
using namespace std;

int map[16][16];
bool book[16][16];
int n, m;

void dfs(int x, int y, int type)
{
    if (x<0||y<0||x>n||y>m||book[x][y])
    {
        return;
    }
    if (x == n-1&&y == m )
    {
        cout <<"成功寻找路径"<<endl;
        return;
    }
    if (map[x][y]<=4)
    {
        switch (type)
        {
            case 1: {
                book[x][y]=true;
                dfs(x+1, y, 2);	//方块三
                dfs(x-1, y, 4);	//方块四
                book[x][y] = false;
                break;
            }
            case 2: {
                book[x][y] = true;
                dfs(x , y+1, 1);	//方块一
                dfs(x, y - 1, 3);	//方块四
                book[x][y] = false;
                break;
            }
            case 3: {
                book[x][y] = true;
                dfs(x-1, y, 4);	//方块一
                book[x][y] = false;
                break;
            }
            case 4: {
                book[x][y] = true;
                dfs(x, y + 1, 1);	//方块二
                dfs(x, y - 1, 3);	//方块四
                book[x][y] = false;
                break;
            }
        }
    }
    else if (map[x][y]<=6)
    {
        switch (type)
        {
            case 1: {
                book[x][y] = true;
                dfs(x, y + 1, 1);	//方块5
                book[x][y] = false;
                break;
            }
            case 2: {
                book[x][y] = true;
                dfs(x+1, y, 2);	//方块6
                book[x][y] = false;
                break;
            }
            case 3: {
                book[x][y] = true;
                dfs(x , y-1, 3);	//方块5
                book[x][y] = false;
                break;
            }
            case 4: {
                book[x][y] = true;
                dfs(x -1, y, 4);	//方块6
                book[x][y] = false;
                break;
            }
        }
    }

}

int main()
{
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> map[i][j];
        }
    }
    dfs(0, 0, 1);

    return 0;
}

/*
5 4
5 3 5 3
1 5 3 0
2 3 5 1
6 1 1 5
1 5 5 4
*/